/*
 * @lc app=leetcode.cn id=171 lang=javascript
 *
 * [171] Excel 表列序号
 */

// @lc code=start
/**
 * @param {string} columnTitle
 * @return {number}
 */
var titleToNumber = function (columnTitle) {
  const charVal = (char) => {
    return char.charCodeAt() - 64;
  };

  let level = 0;
  let ans = 0;
  while (columnTitle) {
    const char = columnTitle[columnTitle.length - 1];
    ans += Math.pow(26, level) * charVal(char);

    columnTitle = columnTitle.substring(0, columnTitle.length - 1);
    level++;
  }

  return ans;
};
// @lc code=end

// @after-stub-for-debug-begin
module.exports = titleToNumber;
// @after-stub-for-debug-end
